
interface markFace {
    width: number,
    height: number,
    text?: string,
    textColor?: string,
    textSize: string,
    img?: string,
    rotate?: number
}
export default function weaterMark(markObj: markFace): string {
    let cavs = document.createElement("canvas");
    cavs.width = markObj.width;
    cavs.height = markObj.height;
    let cxt = cavs.getContext("2d");
    if (markObj.text && cxt) {
        //cxt.clearRect(0, 0, markObj.width, markObj.height);  //绘制之前画布清除
        cxt.font = markObj.textSize;
        cxt.rotate(markObj.rotate || 45 * Math.PI / 180);
        cxt.fillStyle = markObj.textColor || "RGBA(255, 0, 0,.2)";
        cxt.fillText(markObj.text, markObj.width / 2, -markObj.height / 2);
    }
    if (markObj.img) {
        let image = new Image();
        image.src = markObj.img;
        image.onload = function () {
            cxt?.drawImage(image, 0, 0)
        }
    }
    let url: string = cavs.toDataURL()
    return url;
}